package com.class06.service.impl;

import com.class06.dao.StudentDao;
import com.class06.exception.MyException;
import com.class06.pojo.Student;
import com.class06.service.StudentService;

import java.util.List;

public class StudentServiceImpl implements StudentService{
    private StudentDao studentDao;

//    使用set方法，注入StudentDao对象
    public void setStudentDao(StudentDao studentDao) {
        this.studentDao = studentDao;
    }
    @Override
    public List<Student> getAllStudent() {
        return studentDao.queryAllStudent();
    }

    @Override
    public int addStudent(Student student) {
        return studentDao.addStudent(student);

    }

    @Override
    public int deleteStudent(Integer id) {
        if (id==null||id==0){

//            throw 与 throws的区别：
//            throw 抛出异常    throws 声明异常
//            理解：上游排污 ，下游治污
            throw new MyException("id不能为空");
        }
        return studentDao.deleteStudent(id);
    }

    @Override
    public int updateStudent(Student student) {
        if (student==null){
            throw new MyException("学生信息不能为空");
        }
        return studentDao.updateStudent(student);

    }
}
